package com.homestead;

import org.springframework.boot.Banner;
import org.springframework.boot.SpringBootVersion;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.ansi.AnsiStyle;
import org.springframework.core.env.Environment;

import java.io.PrintStream;

/**
 * @author HanBin_Yang
 * @since 2021/7/4 22:00
 */
public class CouponsBanner implements Banner {

    private static final String[] BANNER = { "", "________     ______\n" +
            "___  __/________  /_       ________________  ______________________________\n" +
            "__  /_ _  ___/_  __ \\_______  ___/  __ \\  / / /__  __ \\  __ \\_  __ \\_  ___/\n" +
            "_  __/ / /__ _  /_/ //_____/ /__ / /_/ / /_/ /__  /_/ / /_/ /  / / /(__  )\n" +
            "/_/    \\___/ /_.___/       \\___/ \\____/\\__,_/ _  .___/\\____//_/ /_//____/\n" +
            "                                              /_/" };

    private static final String SPRING_BOOT = " :: Spring Boot :: ";

    private static final int STRAP_LINE_SIZE = 42;

    @Override
    public void printBanner(Environment environment, Class<?> sourceClass, PrintStream printStream) {
        for (String line : BANNER) {
            printStream.println(AnsiOutput.toString(AnsiColor.BRIGHT_YELLOW, line));
        }
        String version = SpringBootVersion.getVersion();
        version = (version != null) ? " (v" + version + ")" : "";
        StringBuilder padding = new StringBuilder();
        while (padding.length() < STRAP_LINE_SIZE - (version.length() + SPRING_BOOT.length())) {
            padding.append(" ");
        }

        printStream.println(AnsiOutput.toString(AnsiColor.GREEN, SPRING_BOOT, AnsiColor.DEFAULT, padding.toString(),
                AnsiStyle.FAINT, version));
        printStream.println();
    }
}
